package mtyan;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ControllerServlet
 */
public class ControllerServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ControllerServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
	
    public void init(ServletConfig config) throws ServletException {
    	ServletContext context = config.getServletContext();
    	context.setAttribute("base", config.getInitParameter("base"));
    	super.init(config);
    }
    
	public void doGet (HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException{
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url = "/Events.jsp";
		String action = request.getParameter("action");
		if (action.equals("addEvent") || action.equals("addComment")){
			url = "/Events.jsp";
		} else if (action.equals("showAddEvent")){
			url = "/AddEvent.jsp";
		} else if (action.equals("showAddComment")){
			url = "/addComment.jsp";
		}
		ServletContext context = getServletContext();
		RequestDispatcher requestDispatcher = context.getRequestDispatcher(url);
		requestDispatcher.forward(request, response);
		
	}

}
